﻿<%@ Page Language="C#" Title="路面结构管理" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="B_PmstcPage.aspx.cs" Inherits="STHPMS1.Web.W_View.Basis.B_PmstcPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Enum.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/JsPage.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Appearance.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Bussiness.js")%>
            <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>  

    <script type="text/javascript">     
        var _view = new JsPage();
        var _css = new Appearance();
        var _bus = new Bussiness();

        function onAddClick() {
            _view.AddAction();
        }
        function onEditClick() {
            _view.EditAction();
        }
        function onRemoveClick() {
            _view.RemoveAction();
        }
        function onSumbitClick() {
            _view.sumbitForm();
        }
        function onCloseClick() {
            _view.closeDialog();
        }

        function onSearchClick(n, o) {
            var road = $('#cmbSearch').combobox("getValue");

            var data = [];
            data.push({ key: "road", value: road });

            _view.SearchAction(data);
        }

        $(function () {
            $("#btnAdd").on("click", onAddClick);
            $("#btnEdit").on("click", onEditClick);
            $("#btnDel").on("click", onRemoveClick);
            $("#btnSave").on("click", onSumbitClick);
            $("#btnCancel").on("click", onCloseClick);
            $("#btnLayer").on("click", show_layer);
            $("#btnSave1").on("click", save_layer);
            $("#btnCancel1").on("click", close_layer);
            $("#cmbSearch").combobox({ onChange: onSearchClick });
            $("#Pvmttype_Dictid").combobox({ onSelect: change_pvmttype });
            
            _view.setForm($('#fm'))
              .setDialog($('#dlg'))
              .setDataGrid($('#dg'))
              .loadDataGrid("/api/pmstc");

        })

        function change_pvmttype(rect) {
            var data = EnumEx.getDicts(RoadBasicTypeEnum, function (id) {
                if (rect.id == PavementTypeEnum.P21)
                {
                    if (id < RoadBasicTypeEnum.B171)
                        return true;
                }
                else if (rect.id == PavementTypeEnum.P22) {
                    if (id >= RoadBasicTypeEnum.B171)
                        return true;
                }
                else if (rect.id == PavementTypeEnum.P23) {
                    if (id == RoadBasicTypeEnum.B167)
                        return true;
                }
                return false;
            });

            $('#Basictype_Dictid').combobox('loadData', data).combobox('clear');
        }

        function show_layer()
        {
            editIndex = undefined;
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '编辑层时，请选择一项!', 'warning');
                return;
            }

            $("#dg1").datagrid({ url: '/api/pmstc/lays?struid=' + encodeURI(row.Struid), onClickRow: onClickRow1 });
            $("#dlg1").dialog('open');
        }

        function close_layer()
        {
            $("#dlg1").dialog('close');
        }

        function save_layer() {
            var rows = $('#dg1').datagrid('getRows');
            if (rows)
            {
                $('#dg1').datagrid('endEdit', editIndex);
                var data = [];

                var j = 0;;
                for (var i = 0; i < rows.length; i++) {
                    var obj1 = rows[i];
                    data.push(obj1);
                }
                
                var row = $('#dg').datagrid('getSelected');

                $.messager.progress({
                    title: '请等待',
                    msg: '加载数据中...'
                });
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/api/pmstc/lay_save',
                    cache:false,
                    data: { rdwayid: row.Rdwayid, direction_Dictid: row.Direction_Dictid, struid: row.Struid, mates: JSON.stringify(data) },
                    complete: function () {
                        $.messager.progress('close');
                    },
                    success: function (thicks) {
                        $('#dg').datagrid('reload');
                        close_layer();
                        editIndex = undefined;
                    },
                    error: Common.ShowError
                });
            }
        }
    </script>    

    
	<script type="text/javascript">
	    var editIndex = undefined;
	    function endEditing() {
	        if (editIndex == undefined) { return true }
	        if ($('#dg1').datagrid('validateRow', editIndex)) {

	            var statu = getDataGridCell(editIndex, "status");
	            if (statu && !statu.target[0].checked)
	            {
	                cmbClear(editIndex);
	            }
	            $('#dg1').datagrid('endEdit', editIndex);

	            editIndex = undefined;
	            return true;
	        } else {
	            return false;
	        }
	    }

	    function onClickRow1(index) {
	        if (editIndex != index) {
	            if (endEditing()) {
	                $('#dg1').datagrid('selectRow', index)
							.datagrid('beginEdit', index);

	                editIndex = index;
	                comboboxBinding(index);
	            } else {
	                $('#dg1').datagrid('selectRow', editIndex);
	            }
	        }
	    }

	    function comboboxBinding(index) {
	        var target = $('#dg1').datagrid('getEditor', { 'index': index, 'field': 'Stru_Id' }).target;
	        target.combobox('clear'); 

	        var layer = $('#dg1').datagrid('getRows')[index].Layer_dictid;
	        if (layer) {
	            var url = '/api/pmstc/mates?lay=' + layer;
	            target.combobox('reload', url);
	        }
	    }

	    function cmbSelect(rect)
	    {
	        var index = editIndex;
	        if ($('#dg1').datagrid('getRows')[editIndex]) {
	            setComboboxValue(editIndex, "Poirat", rect.poirat);
	            setComboboxValue(editIndex, "Elamod", rect.elamod);
	            setComboboxValue(editIndex, "Layercoeff", rect.layercoeff);
	            setComboboxValue(editIndex, "Draincoeff", rect.draincoeff);
	        }
	    }

	    function cmbOnLoadSuccess(rows)
	    {
	        var row=$('#dg1').datagrid('getRows')[editIndex];
	        if(row)
	        {
	            $(this).combobox('setValue', row.Stru_Id);
	        }    
	    }

	    function cmbClear(index) {
	        if ($('#dg1').datagrid('getRows')[index]) {

	            if (getDataGridCell(index, 'Stru_Id') == null) return;

	            getDataGridCell(index, "Stru_Id").target.combobox('clear');
	            setComboboxValue(editIndex, "Thick", null);
	            setComboboxValue(editIndex, "Poirat", null);
	            setComboboxValue(editIndex, "Elamod", null);
	            setComboboxValue(editIndex, "Layercoeff", null);
	            setComboboxValue(editIndex, "Draincoeff", null);
	        }
	    }

	    function setComboboxValue(index, col, val) {
	        var ed = getDataGridCell(index, col);
	        if (!val)
	            ed.target.numberbox('clear');
	        else
	            ed.actions.setValue(ed.target, val);
	    }
        
	    function getDataGridCell(index, col)
	    {
	        return $('#dg1').datagrid('getEditor', { index: index, field: col });
	    }

	</script>

    <script>
        //导入的点击事件
        function impt() {
            $("#linkUpload").text("上传");

            $('#dlgImport').dialog('open');
        }

        function closeFile() {
            $("#linkUpload").text("上传");
            $('#dlgImport').dialog('close');
            $("#fileHid").val('');//清空隐藏域
        }
        //上传
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '/api/pmstc/uploadFile', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'file1', //文件上传域的ID
                    dataType: 'string', //返回值类型 一般设置为json
                    success: function (data)  //服务器成功响应处理函数
                    {
                        //写入隐藏域
                        $("#fileHid").val(data);
                        $("#linkUpload").text("上传成功");
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);

                    }
                }
            )
            return false;
        }
        //上传文件验证
        function upLoad() {
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                ajaxFileUpload();
            }
        }
        //导入处理
        function saveFile() {
            var file = $("#fileHid").val();//上传后的Excel路径
            if (file == "") {
                alert("请上传数据文件");
                return;
            }
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/pmstc/saveFile?file=" + encodeURI(file),
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    $("#fileHid").val('');//清空隐藏域
                    $('#dlgImport').dialog('close');
                    $.messager.progress('close');
                    _view.loadDataGrid();
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeFile();
                }
            });
        }

    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">    
   
    <div id="tb">
        <a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" >添加结构</a>
        <a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >编辑结构</a>
        <a id="btnLayer" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >编辑层</a>
        <a id="btnDel" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" >删除结构</a>
         <a href="/down?type=lmjg" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">模板下载</a>
        <a id="btnImpt" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true" onclick="impt()">导入</a> 
        <select id="cmbSearch" class="easyui-combobox" style="width:100px" data-options="prompt:'路线编号',url:'/api/roadway/dict',method:'get',valueField:'id',textField:'id',panelHeight:80">
        </select>
    </div>
    

     <div id="dlg-buttons">
		<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" >保存</a>
		<a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
	</div>

     <div id="dlg-buttons1">
		<a id="btnSave1" href="javascript:void(0)" class="easyui-linkbutton" >保存</a>
		<a id="btnCancel1" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
	</div>

    <table id="dg" class="easyui-datagrid content-place"   data-ajaxcached="false"  data-options='{
                  "title": "路面结构列表",
                  "toolbar": "#tb",
                  "method": "get",
                  "iconCls": "icon-edit",
                  "width": "auto",
                  "height": "auto",
                  "nowrap": false,
                  "striped": true,
                  "border": true,
                  "collapsible": false,
                  "fit": false,
                  "singleSelect": true,
                  "rownumbers": true,
                  "pagination": true
                }' >
        <thead>
            <tr>
                <th data-options="field:'Struid',editor:'text',width:80,align:'center',hidden:true">路面结构编号</th>
                <th data-options="field:'Rdwayid',editor:'text',width:100,align:'center' ">路线编号</th>
                <th data-options="field:'Beginmp',editor:'numberbox',width:80,align:'center' ,formatter:_css.formatStake ">起点桩号</th>
                <th data-options="field:'Endmp',editor:'numberbox',width:80,align:'center' ,formatter:_css.formatStake ">终点桩号</th>
                <th data-options="field:'Direction_Dictid',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum">行车方向</th>
                <th data-options="field:'Pvmttype_Dictid',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum" >面层类型</th>
                <th data-options="field:'Basictype_Dictid',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum" >基层类型</th>
                <th data-options="field:'Cbr',editor:'numberbox',width:80,align:'center' ,min:0,precision:2">路基CBR</th>
                <th data-options="field:'Degdf',editor:'numberbox',width:160,align:'center',min:0,precision:2 ">设计弯沉(0.01mm)</th>
                <th data-options="field:'Thick_T',editor:'numberbox',width:100,align:'center',min:0,precision:2 ">结构总厚度(cm)</th>
                <th data-options="field:'Thick_S',editor:'numberbox',width:100,align:'center',min:0,precision:2 ">面层总厚度(cm)</th>
                <th data-options="field:'His_Version',editor:'numberbox',width:20,align:'center',hidden:true ">养护版本</th>
            </tr>
        </thead>
    </table>
   
    <div id="dlg" class="easyui-dialog" title="保存数据" style="width:370px;height:320px;padding:10px" data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'
			">
        <form id="fm" method="post" action="/api/pmstc"  class="easyui-form" data-options="novalidate:true">
            <table>			 
                <tr style="display:none">
                    <td>路面结构段:</td>   
                    <td><input name='Struid' class=" easyui-textbox" /></td>
                </tr>
                <tr>
                    <td>路线编号:</td>                    
                    <td><input id="Rdwayid" name='Rdwayid'  class="easyui-combobox" data-options="prompt:'路线编号',required:true,valueField:'Rdwayid',textField:'Name',url:'/api/roadway/all',method:'get',validType:'MaxLength[20]' "/></td>
                </tr>
                <tr>
                    <td>起点桩号:</td>
                    <td><input name='Beginmp' class=' easyui-numberbox' data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>
                <tr>
                    <td>终点桩号:</td>
                    <td><input name='Endmp' class=' easyui-numberbox' data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>                
                <tr>
                    <td>行车方向:</td>
                     <td><input id="Direction_Dictid" name='Direction_Dictid' class=' easyui-combobox'  data-options="required:true,prompt:'行车方向',valueField:'id',textField:'text',panelHeight:'auto',url:'/api/data/direction',method:'get'" /></td>
                </tr>
                <tr>
                    <td>面层类型:</td>                    
                    <td><input id="Pvmttype_Dictid" name='Pvmttype_Dictid'  class="easyui-combobox" data-options="required:true,prompt:'路面类型',valueField:'id',textField:'text',url:'/api/data/pavement',method:'get' ,panelHeight:'auto'"/></td>
                </tr>
                <tr>
                    <td>基层类型:</td>                    
                    <td><input id="Basictype_Dictid" name='Basictype_Dictid'  class="easyui-combobox" data-options="prompt:'基层类型',valueField:'id',textField:'text',method:'get',panelHeight:'auto' "/>
                    </td>
                </tr>
                <tr>
                    <td>路基CBR:</td>
                    <td><input name='Cbr' class='easyui-numberbox' data-options="min:0,precision:2"/></td>
                </tr>
                <tr>
                    <td>设计弯沉(0.01mm):</td>
                    <td><input name='Degdf' class='easyui-numberbox' data-options="min:0,precision:2"/></td>
                </tr>
                <tr style="display:none">
                    <td>结构总厚度(cm):</td>
                    <td><input name='Thick_T' class='easyui-numberbox' data-options="min:0,precision:2" /></td>
                </tr>
                <tr style="display:none">
                    <td>结构总厚度(cm):</td>
                    <td><input name='Thick_S' class='easyui-numberbox' data-options="min:0,precision:2" /></td>
                </tr>
                 <tr style="display:none">
                    <td>养护版本:</td>
                    <td><input name='His_Version' class='easyui-numberbox' /></td>
                </tr>
		    </table>
        </form>
    </div>

      <div id="dlg1" class="easyui-dialog" title="编辑层" style="width:750px;height:315px;padding:10px" data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons1'
			">          
            <table id="dg1" style="width:700px;height:auto"
			        data-options="
				        iconCls: 'icon-edit',
				        singleSelect: true,
				        method: 'get'
			        ">
		        <thead>
			       	<tr>
				        <th data-options="field:'status',width:60,align:'center',editor:{type:'checkbox',options:{on:'已使用',off:'未使用'}}">状态</th>
				        <th data-options="field:'Layer_name',width:80,align:'center'">层</th>
				        <th data-options="field:'Stru_Id',width:130,align:'center',
						        formatter:function(value,row)
                                {
							        return row.Stru_Id;
						        },
						        editor:
                                {
							        type:'combobox',
							        options:
                                    {
								        valueField:'id',
								        textField:'id',
				                        method: 'get',
                                        onSelect:cmbSelect,
                                        onLoadSuccess:cmbOnLoadSuccess
							        }
                                }">材料名称</th>
				        <th data-options="field:'Thick',width:80,align:'center',editor:{type:'numberbox',options:{precision:0,min:0,max:100}},required:true">厚度(cm)</th>
				        <th data-options="field:'Poirat',width:80,align:'center',editor:{type:'numberbox',options:{precision:2,min:0,max:1}}">泊松比</th>
				        <th data-options="field:'Elamod',width:100,align:'center',editor:{type:'numberbox',options:{precision:0,min:0,max:50000}},required:true">回弹模量(mpa)</th>
				        <th data-options="field:'Layercoeff',width:80,align:'center',editor:{type:'numberbox',options:{precision:2,min:0,max:1}}">层系数</th>
				        <th data-options="field:'Draincoeff',width:80,align:'center',editor:{type:'numberbox',options:{precision:2,min:0,max:2}}">排水系数</th>
			        </tr>
		        </thead>
	        </table>
    </div>

     <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 400px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">      
            <table>
                <tr>
                    <td style="width:80px;">导入源:</td>
                    <td>
                        
                        <input id="fileHid" type="hidden" />
                        <input type="file" id="file1" name="file" style="width: 200px"/>
                        <a href="javascript:void(0)" id="linkUpload"  onclick="javascript:upLoad();">上传</a>
                    </td>
                </tr>
                
            </table>
       
    </div>
    <!--导入数据命令-->
     <div id="dlg-buttonsImport">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:saveFile();">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:closeFile()">取消</a>
    </div>
</asp:Content>
